#Generator of the necesary token classes basing upon a file formatted as follows:
#TkName TkValue

appFile = File.new("src/app.rb", "w")
tokens = Array.new()

IO.foreach("src/tokens.txt") do |line|
  tkInfo = line.split(" ")
  outFile = File.new("src/tokens/Tk#{tkInfo[0]}.rb", "w")
  outFile.syswrite(
    "require \"tokens/Token.rb\"\n" +
    "# = Class Tk#{tkInfo[0]}\n" +
    "# Implementation of abstract class Token, which describes the token\n" +
    "# corresponding to the match of regular expression /" + tkInfo[2] + "/\n" +
    "# Inherits all attributes and methods from the parent class\n" +
    "class Tk#{tkInfo[0]} < Token\n" +
    "  @@regexp = /#{tkInfo[2]}/\n" +
    "  @@kind = \"#{tkInfo[1]}\"\n" +
    "  @sym = :Tk#{tkInfo[0]}\n" +
    "# == Method initialize\n" +
    "# Constructor for the class Tk#{tkInfo[0]}\n" +
    "# === Parameters\n" +
    "# * row: Row of the input file in whích the token was found\n" +
    "# * column: Column of the input file in which the token was found\n" +
    "# * value: Expression in file that matched regular expression: #{tkInfo[2]}\n" +
    "  def initialize(row, column, value)\n" +
    "    @row = row\n" +
    "    @column = column\n" +
    "    @value = value\n" +
    "  end\n" +
    "\n"+
    "# == Method getRegexp\n" +
    "# Method to obtain class attribute @@regexp as a string\n" +
    "  def Tk#{tkInfo[0]}.getRegexp\n" +
    "    return @@regexp\n" +
    "  end\n" +
    "# == Method getKind\n" +
    "# Method to obtain class kind @@kind as a string\n" +
    "  def Tk#{tkInfo[0]}.getKind\n" +
    "    return @@kind\n" +
    "  end\n" +    "end\n"
  )
  tokens.push("Tk" + tkInfo[0])
end

appFile.syswrite("$tokens = Array[\"" + tokens.join("\", \"") + "\"]\n")
